//
//  CheckShopViewController.m
//  YiBaoStore
//
//  Created by 吕清毅 on 2018/10/2.
//  Copyright © 2018年 小河. All rights reserved.
//

#import "CheckShopViewController.h"
#import "BasicWebViewController.h"

@interface CheckShopViewController ()
@property (nonatomic, strong) UIScrollView *mainScroll;
@end

@implementation CheckShopViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
    self.bgNavView.hidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setHeadView];
    [self checkIpResult];
}

#pragma mark -- 查询店铺状态 如果是1，跳转首页
- (void)checkIpResult
{
    [[HttpRequest currentHttpRequest]postPath:ShopState_API params:nil resultBlock:^(id Data, MsgModel *msgModel)
    {
        if (msgModel.status == 200) {
            NSString *statue = Data[@"result"];
            if ([statue integerValue] == 1) {
                //注册完成
                dispatch_async(dispatch_get_main_queue(), ^{
                    MYHTabBarController *tab = [MYHTabBarController new];
                    AppDelegate* app = (AppDelegate *)[UIApplication sharedApplication].delegate;
                    app.window.rootViewController = tab;
                });
            }
            else if([statue integerValue]==-10)
            {
                 dispatch_async(dispatch_get_main_queue(), ^{
                     ADDNewShopViewController *addVC = [ADDNewShopViewController new];
                     addVC.isFailure = YES;
                     AppDelegate* app = (AppDelegate *)[UIApplication sharedApplication].delegate;
                     app.window.rootViewController = [[UINavigationController alloc]initWithRootViewController:addVC];
                 });
            }
            else
            {
                
            }
                
        }
         [self.mainScroll.mj_header endRefreshing];
    }];
}

- (void)getNewData
{
    [self checkIpResult];
}

- (void)setHeadView
{
    self.mainScroll = [UIScrollView new];
    self.mainScroll.frame = CGRectMake(0, TopStatusHeight, SCREENWIDTH, SCREENHEIGHT-TopStatusHeight);
    self.mainScroll.backgroundColor = ClearColor;
    self.mainScroll.contentSize = CGSizeMake(SCREENWIDTH,SCREENHEIGHT);
    [self.view addSubview:self.mainScroll];
    
    self.mainScroll.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(getNewData)];
    
    UIView *headView = [UIView new];
    headView.frame = CGRectMake(0, 0, SCREENWIDTH, 330);
    headView.backgroundColor = UIColorFromHex(0xF8F5ED);
    [self.mainScroll addSubview:headView];
    
    UIImageView *checkIV = [UIImageView new];
    CGFloat left = (SCREENWIDTH - 295)/2;
    checkIV.frame = CGRectMake(left, 330-82-166, 295, 166);
    checkIV.image = [UIImage imageNamed:@"shopCheck"];
    [headView addSubview:checkIV];
    
    UIView *lineView = [UIView new];
    lineView.frame = CGRectMake(0, headView.height-1, SCREENWIDTH, 1);
    lineView.backgroundColor = goldColor;
    [headView addSubview:lineView];
    
    UILabel *titleLab = [UILabel new];
    titleLab.frame = CGRectMake(0, headView.bottom+30, SCREENWIDTH, 30);
    titleLab.textColor = titleColor;
    titleLab.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:22];
    titleLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:2 and:@"等待审核"];
    titleLab.textAlignment = NSTextAlignmentCenter;
    [self.mainScroll addSubview:titleLab];
    
    UILabel *desLab = [UILabel new];
    desLab.frame = CGRectMake(0, titleLab.bottom+15, SCREENWIDTH, 20);
    desLab.textColor = titleColor;
    desLab.font = FontWithSize(14);
    desLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:1.17 and:@"审核通过后您将开启您的小门店大生意之旅"];
    desLab.textAlignment = NSTextAlignmentCenter;
    [self.mainScroll addSubview:desLab];
    
    CGFloat padding = (SCREENWIDTH-35)/2;
    for (int i = 0; i < 3; i++) {
        UIView *iv = [UIView new];
        iv.frame = CGRectMake(padding+15*i, desLab.bottom+15, 5, 5);
        iv.layer.cornerRadius = 5/2;
        iv.layer.masksToBounds = YES;
        iv.backgroundColor = UIColorFromHex(0xD7D7D7);
        [self.mainScroll addSubview:iv];
    }
    
    UIView *bottomView = [UIView new];
    if (@available(iOS 11.0, *)) {
        bottomView.frame = CGRectMake(0, SCREENHEIGHT-51-BottomHeight_xs, SCREENWIDTH, 51);
    } else {
        // Fallback on earlier versions
        bottomView.frame = CGRectMake(0, SCREENHEIGHT-51-BottomHeight, SCREENWIDTH, 51);
    }
    
    bottomView.backgroundColor = TotalWhite;
    [self.mainScroll addSubview:bottomView];
    
    UIView *bottomLine = [UIView new];
    bottomLine.frame = CGRectMake(0, 0, SCREENWIDTH, 1);
    bottomLine.backgroundColor = goldColor;
    [bottomView addSubview:bottomLine];
    
    UIImageView *telIV = [UIImageView new];
    telIV.frame = CGRectMake(40, 18, 16, 16);
    telIV.image = [UIImage imageNamed:@"tel"];
    [bottomView addSubview:telIV];
    
    UILabel *telLab = [UILabel new];
    telLab.frame = CGRectMake(telIV.right+5, 21, 44, 10);
    telLab.textColor = titleColor;
    telLab.font = FontWithSize(10);
    telLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:0.83 and:@"联系电话"];
    [bottomView addSubview:telLab];
    
    UILabel *rightLab = [UILabel new];
    rightLab.frame = CGRectMake(SCREENWIDTH-40-114, 19, 114, 18);
    rightLab.textColor = titleColor;
    rightLab.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:14];
    rightLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:1 and:@"0571-86912156"];
    [bottomView addSubview:rightLab];
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(SCREENWIDTH-154, 20, 114, 20)];
    btn.backgroundColor = [UIColor clearColor];
    [btn addTarget:self action:@selector(push:) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:btn];
    
    self.mainScroll.contentSize = CGSizeMake(SCREENWIDTH, bottomView.bottom);
}

- (void)push:(UIButton *)btn
{
    MYHTabBarController *tab = [MYHTabBarController new];
    AppDelegate* app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    app.window.rootViewController = tab;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
